<template>
    <div class="classify">
        <div class="list">
            <div class="class-item" v-for="(item, index) in info" :key="index">
                <div v-if="item.show" @click="asd(index)">
                    <img :src="item.img" alt=""/>
                    <div class="text-info">
                        <div>{{ item.name }}</div>
                        <div>{{ item.detail }}</div>
                    </div>
                    <img class="arrow" src="../assets/icon/arrow-right.png" alt=""/>
                </div>
            </div>
        </div>
        <footer-item :idx="1"></footer-item>
    </div>
</template>

<script>
    import headerItem from "@/components/header.vue";
    import footerItem from "@/components/footer.vue";

    export default {
        name: "classify",
        components: {
            headerItem,
            footerItem
        },
        data() {
            return {
                linkArr: [
                    "/business",
                    "/callCenter",
                    "/education",
                    "/financial",
                    "/claims"
                ],
                info: "",
                menuList: [
                    "Business/index", // 业务中心
                    "Customer/index", // 客服中心
                    "Edu/index", // 教育中心
                    "Finance/index", // 财务中心
                    "Claim/index" // 理赔中心
                ],
                menuList1: [
                    [
                        {
                            limits: "Business/insurance",
                            url: "/business/insurance?index=0"
                        },
                        {
                            limits: "Business/edu",
                            url: "/business/education?index=1"
                        },
                        {
                            limits: "Business/finance",
                            url: "/business/finance?index=2"
                        },
                        {
                            limits: "Business/hr",
                            url: "/business/human?index=3"
                        },
                        {
                            limits: "Business/advisory",
                            url: "/business/consulting?index=4"
                        },
                        {
                            limits: "Business/service",
                            url: "/business/enterpriseService?index=5"
                        }
                    ],
                    [
                        {
                            limits: "Customer/insurance",
                            url: "/callCenter/kfInsurance?index=0"
                        },
                        {
                            limits: "Customer/finance",
                            url: "/callCenter/kfFinance?index=1"
                        },
                        {
                            limits: "Customer/hr",
                            url: "/callCenter/kfHuman?index=2"
                        },
                        {
                            limits: "Customer/advisory",
                            url: "/callCenter/kfConsulting?index=3"
                        },
                        {
                            limits: "Customer/service",
                            url: "/callCenter/kfEnterpriseService?index=4"
                        }
                    ],
                    [
                        {
                            limits: "Edu/read",
                            url: "/educationHome"
                        }
                    ],
                    [
                        {
                            limits: "Finance/insurance",
                            url: "/financial/jrInsurance?index=0"
                        },
                        {
                            limits: "Finance/edu",
                            url: "/financial/jrEducation?index=1"
                        },
                        {
                            limits: "Finance/finance",
                            url: "/financial/jrFinancial?index=2"
                        },
                        {
                            limits: "Finance/hr",
                            url: "/financial/jrHuman?index=3"
                        },
                        {
                            limits: "Finance/advisory",
                            url: "/financial/jrAdvisory?index=4"
                        },
                        {
                            limits: "Finance/service",
                            url: "/financial/jrEnterpriseService?index=5"
                        }
                    ],
                    [
                        {
                            limits: "Claim/read",
                            url: '/claim'
                        },
                    ],
                ]
            };
        },
        methods: {
            asd(i) {
                localStorage.setItem('iosOK','yes')
                let menu = this.menuList1[i];
                let num = 0;
                menu.map((item, index) => {
                    let url = menu[index].url;
                    if (this.$queryMenu(item.limits)) {
                        this.$router.push(url);
                        return;
                    } else {
                        num = num + 1;
                    }
                    if (menu.length == num) {
                        this.info[1].show = false
                        this.$dialog
                            .alert({
                                title: "温馨提示",
                                message: "您暂无此模块内部权限"
                            })
                            .then(() => {
                            });
                    }
                    return;
                });
            },
            getInfo() {
                this.$post("/api/common/api_menu", {})
                    .then(res => {
                        let menuArr = res.data;
                        menuArr.map((item, index) => {
                            let menu = this.menuList[index];

                            item.show = this.$queryMenu(menu);
                            console.log(item.show, '000000');
                            item.link = this.linkArr[index];
                        });
                        this.info = menuArr;
                        this.showClass()
                    })
                    .catch(err => {
                    });
            },
            showClass() {
                let menu = this.menuList1[1];
                let num = 0;
                menu.map((item, index) => {
                    let url = menu[index].url;
                    if (this.$queryMenu(item.limits)) {
                        return;
                    } else {
                        num = num + 1;
                    }
                    if (menu.length == num) {
                        this.info[1].show = false
                    }
                    return;
                });
                let menuListArr = []
                menuListArr = localStorage.getItem('menuList').split(',')
                if (menuListArr.indexOf('Edu/index') == -1) {
                    this.info[2].show = false
                } else {
                    return true
                }
            },


        },
        created() {
            this.getInfo();
        }
    };
</script>

<style scoped lang="less">
    .classify {
        background-image: linear-gradient(to top, #3fadfe 0%, #366cb3 100%);
        padding-bottom: 10vh;
        padding-top: 48px;
        min-height: 100vh;
        box-sizing: border-box;
    }

    .class-item {
        > div {
            display: flex;
            align-items: center;
            padding: 16px 16px 16px 20px;
            border-radius: 8px;
            background: #fff;
            margin: 0 22px;
            margin-top: 12px;

            img:nth-of-type(1) {
                width: 42px;
                height: 42px;
                border-radius: 50%;
                margin-right: 8px;
            }

            .text-info {
                flex: 1;
                text-align: left;
                padding-left: 10px;

                div:nth-of-type(1) {
                    color: #303442;
                    font-size: 14px;
                }

                div:nth-of-type(2) {
                    color: #73757f;
                    font-size: 12px;
                }
            }

            .arrow {
                width: 11px;
                height: 12px;
            }
        }
    }
</style>